package com.chia.multienty.core.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chia.multienty.core.annotation.WebLog;
import com.chia.multienty.core.domain.basic.Result;
import com.chia.multienty.core.domain.dto.AppSettingDTO;
import com.chia.multienty.core.parameter.wechat.*;
import com.chia.multienty.core.service.AppSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 应用设置 服务
 * </p>
 *
 * @author Multienty Auto Generator
 * @since 2024-06-17
 */
@RestController
@Validated
@RequestMapping("/app-setting")
@RequiredArgsConstructor
@Api(tags = "应用设置")
@ConditionalOnProperty(prefix = "spring.multienty", name = "wechat-module-enabled", havingValue = "true")
public class AppSettingController {

    private final AppSettingService appSettingService;

    @PostMapping("/detail")
    @ApiOperation("获取应用设置详情")
    public Result<AppSettingDTO> getDetail(@Validated @RequestBody AppSettingDetailGetParameter parameter) {
        AppSettingDTO detail = appSettingService.getDetail(parameter);
        return new Result<>(detail);
    }

    @PostMapping("/page")
    @ApiOperation("获取应用设置分页列表")
    public Result<IPage<AppSettingDTO>> getPage(@Validated @RequestBody AppSettingPageGetParameter parameter) {
        IPage<AppSettingDTO> page = appSettingService.getPage(parameter);
        return new Result<>(page);
    }

    @PostMapping("/update")
    @ApiOperation("更新应用设置")
    @WebLog(target = "AppSetting")
    public Result<Boolean> update(@Validated @RequestBody AppSettingUpdateParameter parameter) {
        appSettingService.update(parameter);
        return new Result<>(true);
    }

    @PostMapping("/save")
    @ApiOperation("保存应用设置")
    @WebLog(target = "AppSetting")
    public Result<Boolean> save(@Validated @RequestBody AppSettingSaveParameter parameter) {
        appSettingService.save(parameter);
        return new Result<>(true);
    }

    @PostMapping("/sync")
    @ApiOperation("同步应用设置")
    @WebLog(target = "AppSetting")
    public Result<Boolean> sync(@Validated @RequestBody AppSettingSyncParameter parameter) {
        appSettingService.sync(parameter);
        return new Result<>(true);
    }

    @PostMapping("/enable")
    @ApiOperation("启用应用设置")
    @WebLog(target = "AppSetting")
    public Result<Boolean> enable(@Validated @RequestBody AppSettingEnableParameter parameter) {
        appSettingService.enable(parameter);
        return new Result<>(true);
    }

    @PostMapping("/disable")
    @ApiOperation("禁用应用设置")
    @WebLog(target = "AppSetting")
    public Result<Boolean> disable(@Validated @RequestBody AppSettingDisableParameter parameter) {
        appSettingService.disable(parameter);
        return new Result<>(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除应用设置")
    @WebLog(target = "AppSetting")
    public Result<Boolean> delete(@Validated @RequestBody AppSettingDeleteParameter parameter) {
        appSettingService.delete(parameter);
        return new Result<>(true);
    }

}
